/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.quadbac.measurements;

import java.io.Serializable;

/**
 *
 * @author Steve
 */
@SuppressWarnings("serial")
public class LinearTransform implements ReversibleTransform<Double>, Serializable {

    private Double offset;
    private Double multiplier;

    public LinearTransform() {
    }

    public LinearTransform(Double offset, Double multiplier){
        this();
        this.offset = offset;
        this.multiplier = multiplier;
    }
    /**
     * This constructor creates a LinearTransform based on an existing LinearTransform
     *
     * @param baseTransform
     * @param inputOffset
     * @param inputMultiplier
     */
    public LinearTransform(LinearTransform baseTransform, Double inputOffset, Double inputMultiplier){
        this();
        this.offset = inputOffset + (baseTransform.getOffset() * inputMultiplier);
        this.multiplier = baseTransform.getMultiplier() * inputMultiplier;
    }

    public Double transform(Double input){
        return (input * multiplier) + offset;
    }

    public Double inverse(Double input){
        return (input - offset) / multiplier;
    }

  /**
     * Get the value of offset
     *
     * @return the value of offset
     */
    public Double getOffset(){
        return offset;
    }

  /**
     * Get the value of multiplier
     *
     * @return the value of multiplier
     */
    public Double getMultiplier(){
        return multiplier;
    }

    /**
     * Set the value of offset
     *
     * @param offset new value of offset
     */
    public void setOffset(Double offset) {
        this.offset = offset;
    }
    /**
     * Set the value of multiplier
     *
     * @param offset new value of multiplier
     */
    public void setMultiplier(Double multiplier) {
        this.multiplier = multiplier;
    }

}
